$(function () {
    $("#login_do").click(function () {
        loginway()
    });
    $(document).ready(function (e) {
        $(this).keydown(function (e) {
            if (e.which == "13") {
                loginway()
            }
        })
    });

    function loginway() {
        flag = true;
        var userName = $("#login_name").val();
        var userPwd = $("#login_pwd").val();
        if (!userName.trim()) {
            $("#LoginName").show();
            flag = false
        } else if (!userPwd) {
            $("#LoginPwd").show();
            flag = false
        }
        if (flag) {
            /*
                        sessionStorage['username'] = userName;
                        window.location.href = "index.html";
            */
            $.ajax({
                url: "/sys/adminLogin",
                // url: "http://localhost:8080/sys/adminLogin",
                type: "post",
                async: false,
                dataType: "json",
                data: {
                    username: userName,
                    password: userPwd,
                },
                success: function (data) {
                    if (data.code == 1 && data.msg == "成功") {
                        sessionStorage['username'] = userName;
                        window.location.href = "index.html"
                    }
                    if (data.code == 0) {
                        $('.pass-err').removeClass('hide').find("em").text('用户名或密码有误！');
                        $('.pass-err').find("i").attr('class', 'icon-warn').css("color", "#d9585b");
                    }
                },
                error: function () {
                    $('.pass-err').removeClass('hide').find("em").text('请求超时！');
                    $('.pass-err').find("i").attr('class', 'icon-warn').css("color", "#d9585b");
                }
            })
        }
    }

});
